//
//  AddFriendViewController.m
//  SunXi
//
//  Created by dllo on 15/12/3.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "AddFriendViewController.h"

@interface AddFriendViewController ()

@end

@implementation AddFriendViewController{

    UILabel *_nameLabel;
    UITextField *_namefild;
    UILabel *_messlabel;
    UITextView *_textView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    SV.BC = [UIColor whiteColor];
    self.navigationItem.title = @"添加好友";
    [self initNew];
}
- (void)initNew{
    _nameLabel = [[UILabel alloc]init];
    [SV addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(SV);
        make.top.equalTo(SV).offset(20);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(SV.mas_width);
    }];
    _nameLabel.text = @"好友账号";
    _nameLabel.textAlignment = 1;
    _namefild = [[UITextField alloc]init];
    [SV addSubview:_namefild];
    CGFloat WEI = WIDTH - 40;
    [_namefild mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(SV);
        make.width.mas_equalTo(WEI);
        make.top.equalTo(_nameLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(20);
    }];
    _namefild.placeholder = @"请输入用户账号";
    
    UIView *namexian = [[UIView alloc]init];
    [SV addSubview:namexian];
    namexian.BC = BUTTONCOLOR;
    [namexian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(SV);
        make.width.mas_equalTo(WEI);
        make.top.equalTo(_namefild.mas_bottom).offset(2);
        make.height.mas_equalTo(1);
    }];
    
    
    _messlabel = [[UILabel alloc]init];
    [SV addSubview:_messlabel];
    [_messlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(SV);
        make.width.mas_equalTo(WEI);
        make.top.equalTo(namexian.mas_bottom).offset(20);
        make.height.mas_equalTo(20);
    }];
    _messlabel.text = @"验证消息";
    _messlabel.textAlignment = 1;
    
    _textView = [[UITextView alloc]init];
    [SV addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(SV);
        make.width.mas_equalTo(WEI);
        make.top.equalTo(_messlabel.mas_bottom).offset(20);
        make.height.mas_equalTo(80);
    }];
    _textView.layer.borderWidth = 1;
    _textView.layer.borderColor = BUTTONCOLOR.CGColor;
    _textView.text = @"我想加您为好友";
    UIButton *Addbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    [SV addSubview:Addbutton];
    [Addbutton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(SV).offset(40);
        make.right.equalTo(SV).offset(-40);
        make.centerY.equalTo(SV);
        make.height.mas_equalTo(30);
    }];
    [Addbutton setTitle:@"添加" forState:UIControlStateNormal];
    Addbutton.tintColor = [UIColor whiteColor];
    Addbutton.BC = BUTTONCOLOR;
    Addbutton.layer.cornerRadius = 5;
    [Addbutton addTarget:self action:@selector(AddClick) forControlEvents:UIControlEventTouchUpInside];
}
- (void)AddClick{
    EMError *error = nil;
    BOOL isSuccess = [[EaseMob sharedInstance].chatManager addBuddy:_namefild.text message:_textView.text error:&error];
    if (isSuccess && !error) {
        NSLog(@"添加成功");
        [ShowMytext showAlertViewTitlt:@"提示" message:@"添加成功,请等待对方同意" selector:self Block:^{
            _namefild = nil;
            _textView.text = @"我想加您为好友";
        }];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)presentLeftMenuViewController:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
